home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS21.ADF / ExtraHalfBright / EHB.c < prev    next >
C/C++ Source or Header  |  1989-01-27  |  5KB  |  277 lines

  1. /*  :ts=8 bk=0
  2.  *
  3.  * ehb.c:    Program that lets you see if you have EXTRA_HALFBRITE
  4.  *        mode in your system.  Much more obvious than the previously
  5.  *        published program.
  6.  *
  7.  * Leo L. Schwab            8706.16        (415)-456-6565
  8.  */
  9. #include <exec/types.h>
  10. #include <intuition/intuition.h>
  11.  
  12. #define    DEEP        6    /*  # of bitplanes needed for EHB  */
  13. #define    WIDE        320
  14. #define    HIGH        200
  15. #define    XSIZE        (WIDE - 1)
  16. #define    YSIZE        (HIGH - 1)
  17.  
  18. extern void    *OpenLibrary(), *OpenScreen(), *OpenWindow(), *GetMsg();
  19. extern long    VBeamPos(), TextLength();
  20. extern short    rnd();
  21.  
  22.  
  23. struct NewScreen scrdef = {
  24.     0, 0, WIDE, HIGH, DEEP,
  25.     0, 1,
  26.     EXTRA_HALFBRITE,    /*  This is how you ask for EHB mode  */
  27.     CUSTOMSCREEN,
  28.     NULL, NULL, NULL, NULL
  29. };
  30.  
  31. struct NewWindow windef = {
  32.     0, 0, WIDE, HIGH,
  33.     -1, -1,
  34.     CLOSEWINDOW,
  35.     WINDOWCLOSE,
  36.     NULL, NULL, NULL,
  37.     NULL,            /*  This pointer filled in later  */
  38.     NULL,
  39.     0, 0, 0, 0,
  40.     CUSTOMSCREEN
  41. };
  42.  
  43. struct Screen    *scr;
  44. struct Window    *win;
  45. void        *GfxBase, *IntuitionBase;
  46.  
  47.  
  48. main ()
  49. {
  50.     register struct RastPort    *rp;
  51.     register int            i;
  52.     long                x1, y1, x2, y2, ox1, oy1, ox2, oy2;
  53.     int                dx1, dy1, dx2, dy2;
  54.     void                *msg;
  55.  
  56.     openstuff ();
  57.     rp = &scr -> RastPort;
  58.     SetRast (rp, 0L);
  59.  
  60.     rnd ((short) -VBeamPos());
  61.  
  62.     hsl_wheel ();
  63.  
  64.     rp -> Mask = (1 << 5) - 1;    /*  Don't touch 6th plane yet  */
  65.     for (x1=0; x1<100; x1++) {
  66.         SetAPen (rp, x1);
  67.         RectFill (rp, x1, x1, XSIZE-x1, YSIZE-x1);
  68.     }
  69.  
  70.     SetDrMd (rp, COMPLEMENT);
  71.     rp -> Mask = 1 << 5;        /*  Prepare to show halfbrite  */
  72.     RectFill (rp, 0L, 0L, WIDE-1L, HIGH-1L);    /* Dim everything */
  73.     centertext (rp, 90, "Congratulations!");
  74.     centertext (rp, 110, "You have Extra-Halfbrite mode!");
  75.  
  76.     /*  Finish off by drawing an EHB line all over the place  */
  77.     x1 = rnd (WIDE);  x2 = rnd (WIDE);
  78.     y1 = rnd (HIGH);  y2 = rnd (HIGH);
  79.     setdxdy (&dx1, &dy1);
  80.     setdxdy (&dx2, &dy2);
  81.  
  82.     ox1 = -9999;
  83.     FOREVER {
  84.         if (msg = GetMsg (win -> UserPort)) {
  85.             ReplyMsg (msg);
  86.             break;
  87.         }
  88.  
  89.         if (!rnd (43))
  90.             if (rnd (2))
  91.                 setdxdy (&dx1, &dy1);
  92.             else
  93.                 setdxdy (&dx2, &dy2);
  94.  
  95.         x1 += dx1;  y1 += dy1;
  96.         if (x1 > XSIZE || x1 < 0) {
  97.             dx1 = -dx1;
  98.             x1 = x1<0 ? 0 : XSIZE;
  99.         }
  100.         if (y1 > YSIZE || y1 < 0) {
  101.             dy1 = -dy1;
  102.             y1 = y1<0 ? 0 : YSIZE;
  103.         }
  104.         x2 += dx2;  y2 += dy2;
  105.         if (x2 > XSIZE || x2 < 0) {
  106.             dx2 = -dx2;
  107.             x2 = x2<0 ? 0 : XSIZE;
  108.         }
  109.         if (y2 > YSIZE || y2 < 0) {
  110.             dy2 = -dy2;
  111.             y2 = y2<0 ? 0 : YSIZE;
  112.         }
  113.  
  114.         if (ox1 >= 0)
  115.             box (rp, ox1, oy1, ox2, oy2);
  116.         box (rp, x1, y1, x2, y2);
  117.         WaitTOF ();
  118.  
  119.         ox1 = x1;  oy1 = y1;
  120.         ox2 = x2;  oy2 = y2;
  121.     }
  122.  
  123.     closestuff ();
  124. }
  125.  
  126. box (rp, x1, y1, x2, y2)
  127. register struct RastPort *rp;
  128. long x1, y1, x2, y2;
  129. {
  130.     register long tmp;
  131.  
  132.     if (x2 < x1)
  133.         tmp = x2, x2 = x1, x1 = tmp;
  134.  
  135.     if (y2 < y1)
  136.         tmp = y2, y2 = y1, y1 = tmp;
  137.  
  138.     RectFill (rp, x1, y1, x2, y2);
  139. }
  140.  
  141. centertext (rp, y, str)
  142. register struct RastPort *rp;
  143. char *str;
  144. {
  145.     register long len = strlen (str);
  146.  
  147.     Move (rp, (WIDE - TextLength (rp, str, len)) >> 1, (long) y);
  148.     Text (rp, str, len);
  149. }
  150.  
  151. setdxdy (x, y)
  152. register int *x, *y;
  153. {
  154.     *x = rnd (9) - 4;
  155.     *y = rnd (9) - 4;
  156. }
  157.  
  158. /*  This function computes an HSL color wheel (or tries to)  */
  159. hsl_wheel ()
  160. {
  161.     register struct ViewPort    *vp = &scr -> ViewPort;
  162.     register long            r, g, b;
  163.     int                i, sixth;
  164.  
  165.     for (i=0; i<32; i++) {
  166.         sixth = i * 6 >> 5;    /*  i * 6 / 32  */
  167.         switch (sixth) {
  168.         case 0:        /*  Green on rise, red solid  */
  169.             r = 15;
  170.             g = 3*i;
  171.             b = 0;
  172.             break;
  173.         case 1:        /*  Red falling  */
  174.             r = 32 - 3*i;
  175.             g = 15;
  176.             b = 0;
  177.             break;
  178.         case 2:        /*  Blue rising  */
  179.             r = 0;
  180.             g = 15;
  181.             b = 3*i - 48;
  182.             break;
  183.         case 3:        /*  Green falling */
  184.             r = 0;
  185.             g = 64 - 3*i;
  186.             b = 15;
  187.             break;
  188.         case 4:        /*  Red rising  */
  189.             r = 3*i - 80;
  190.             g = 0;
  191.             b = 15;
  192.             break;
  193.         case 5:        /*  Blue falling  */
  194.             r = 15;
  195.             g = 0;
  196.             b = 96 - 3*i;
  197.         }
  198.         SetRGB4 (vp, (long) i, r, g, b);
  199.     }
  200. }
  201.  
  202. openstuff ()
  203. {
  204.     if (!(IntuitionBase = OpenLibrary ("intuition.library", 0L)))
  205.         die ("Mackraz isn't around.\n");
  206.  
  207.     if (!(GfxBase = OpenLibrary ("graphics.library", 0L)))
  208.         die ("Dale is on vacation.\n");
  209.  
  210.     if (!(scr = OpenScreen (&scrdef)))
  211.         die ("Screen wouldn't open.\n");
  212.  
  213.     windef.Screen = scr;
  214.     if (!(win = OpenWindow (&windef)))
  215.         die ("Window painted shut.\n");
  216. }
  217.  
  218. closestuff ()
  219. {
  220.     if (win)        CloseWindow (win);
  221.     if (scr)        CloseScreen (scr);
  222.     if (GfxBase)        CloseLibrary (GfxBase);
  223.     if (IntuitionBase)    CloseLibrary (IntuitionBase);
  224. }
  225.  
  226. die (str)
  227. char *str;
  228. {
  229.     extern long    Output();
  230.  
  231.     Write (Output(), str, (long) strlen (str));
  232.     closestuff ();
  233.     exit (20);
  234. }
  235.  
  236. #asm
  237. *\
  238. *  :ts=8
  239. * Yet Another random number generator.  By Leo Schwab.
  240. * Based on an idea posted on the USENET (Thanks, Sam Dicker!)
  241. * For the Manx assembler.
  242. *
  243. * Calling convention:
  244. *  short rnd (range);
  245. *  short range;
  246. *
  247. * 8606.30
  248. */
  249.  
  250.         public    _rnd
  251.  
  252. _rnd        lea    rndseed,a0    Get address of seed
  253.         move.w    4(sp),d1    Get range argument
  254.         tst.w    d1
  255.         ble.s    setseed        Go reset seed
  256.  
  257.  
  258.         move.l    (a0),d0        Get seed
  259.         ADD.L   D0,D0
  260.         BHI.S   over
  261.         EORI.L  #$1D872B41,D0
  262. over
  263.         move.l    d0,(a0)        Save new seed
  264.         andi.l    #$ffff,d0    Coerce into word
  265.         divu    d1,d0        Divide by range
  266.         swap    d0         and get remainder (modulus)
  267.         rts
  268.  
  269. setseed        neg.w    d1        Probably don't need this
  270.         move.l    d1,(a0)
  271.         rts
  272.  
  273.         dseg
  274. rndseed        dc.l    0
  275.         cseg
  276. #endasm
  277.